/*******************************************************************************
 * copyright (c) 2009 - 2010 Simon Allen
 *
 * This file is part of Convex Media Converter.
 *
 * Convex Media Converter is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Convex Media Converter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Convex Media Converter; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ******************************************************************************/


#ifndef PREFERENCES_H
#define PREFERENCES_H

#include "OutputSettings/outputsettings.h"

#include <QDialog>


/** Preferences class is a member of the namespace of Ui classes. */
namespace Ui
{
	class Preferences;
}

/**
  * Class for presenting the preferences dialog with user-configured settings and
  * their default values.
  */
class Preferences : public QDialog
{
	Q_OBJECT

	private:
		Ui::Preferences *ui; /**< Pointer to user interface class. */
		PresetSettings *settings; /**< Pointer to program settings. */

		void readSettings(); /**< Read and store program settings. */

	public:
		/** QSettings keys for program settings. */
		const static char *SETTING_APPLICATION_ID;
		const static char *SETTING_SHUTDOWN_WHEN_DONE;
		const static char *SETTING_SHOW_NOTIFICATIONS;
		const static char *SETTING_DEFAULT_OUTPUT_DIR;
		const static char *SETTING_FFMPEG_LOCATION;
		const static char *SETTING_SAVE_WINDOW_GEOMETRY;
		const static char *SETTING_GEOMETRY;

		/**
		  * Initialisation constructor sets up UI.
		  * @param newSettings Pointer to program QSettings.
		  * @param parent Parent widget.
		  */
		Preferences(PresetSettings *newSettings, QWidget *parent = 0);
		~Preferences();

		void readPresets(); /**< Read preset info into preferences window. */

		/**
		  * Returns the current FFmpeg binary location.
		  * @return QString representing FFmpeg location.
		  * @see selectFFmpegLocation()
		  */
		QString getFFmpegLocation() const
		{ return settings->value(SETTING_FFMPEG_LOCATION).toString(); }

		/**
		  * Checks whether notifications are to be shown about the conversion
		  * progress.
		  * @return bool representing notification status.
		  * @see setShowNotifications()
		  */
		bool getShowNotifications() const
		{ return settings->value(SETTING_SHOW_NOTIFICATIONS).toBool(); }

		/**
		  * Checks whether the computer will shutdown when conversion finished.
		  * @return bool representing if computer will shutdown when finished.
		  * @see setShutdownWhenDone(bool shutdown)
		  */
		bool getShutdownWhenDone() const
		{ return settings->value(SETTING_SHUTDOWN_WHEN_DONE).toBool(); }

	public slots:
		/** Uses file dialog to select the default output location. */
		void selectOutputDir();

		/**
		  * Uses file dialog to select FFmpeg binary location.
		  * @see getFFmpegLocation()
		  */
		void selectFFmpegLocation();

		/**
		  * Sets whether notifications are to be shown about conversion
		  * progress.
		  * @param show Boolean representing new notification status.
		  * @see getShowNotification()
		  */
		void setShowNotifications(const bool show)
		{ settings->setValue(SETTING_SHOW_NOTIFICATIONS, show); }

		/**
		  * Sets whether computer is to shutdown when conversion finished.
		  * @param shutdown True if computer is to be shut down when done.
		  * @see getShutdownWhenDone()
		  */
		void setShutdownWhenDone(const bool shutdown)
		{ settings->setValue(SETTING_SHUTDOWN_WHEN_DONE, shutdown); }

		/**
		  * Sets whether window geometry is to be saved.
		  * @param save Bool representing preference.
		  */
		void setSaveWindowGeometry(const bool save)
		{ settings->setValue(SETTING_SAVE_WINDOW_GEOMETRY, save); }

		/** Deletes selected presets from program. */
		void deleteSelectedPresets();
};

#endif // PREFERENCES_H
